<template>
	<view click="page">
		<view class="img">
			<image src="../../static/login/1.png" mode="widthFix"></image>
		</view>

		<view class="text-center" style="padding-top: 80rpx">中国移动认证</view>
		<view class="phone text-center padding30">138****2551</view>

		<view class="login margin30" @click="$tools.route('./setInfo')">本机号码一键登录</view>
		<view class="flex-center margin30">
			<u-checkbox v-model="checked" shape="circle" active-color="#FF5704" label-size="28" size="28">
				<text style="font-size: 20rpx">我已经阅读并同意</text>
				<text @click.stop="$tools.route('../index/webview')" style="font-size: 20rpx; color: #fc132f">《一键登录服务协议》和《隐私政策》</text>
			</u-checkbox>
		</view>
	</view>
</template>

<script>
import WXBizDataCrypt from '@/common/WXBizDataCrypt.js';
export default {
	data() {
		return {
			checked: false
		};
	},
	onShow() {
		// let pc = new WXBizDataCrypt()
		// console.log(pc)
		this.init();
	},
	methods: {
		init() {
			uni.login({
				provider: 'weixin',
				success: (res) => {
					console.log(res);
					this.js_code = res.code;
					uni.request({
						url: 'https://api.weixin.qq.com/sns/jscode2session', // 请求微信服务器
						method: 'GET',
						data: {
							appid: '你的小程序的APPID', //你的小程序的APPID
							secret: '你的小程序秘钥secret, ', //你的小程序秘钥secret,
							js_code: this.js_code, //uni.login 登录成功后的code
							grant_type: 'authorization_code' //此处为固定值
						},
						success(res) {
							console.log('获取信息', res.data);
							this.session_key = res.data.session_key;
						},
						fail(err) {
							console.log(err);
						}
					});
				}
			});
		},
		getPhoneNumber(res) {
			// 获取手机号
			this.phone_encryptedData = res.detail.encryptedData; //用于解密
			this.phone_iv = res.detail.iv; // 用于解密
			console.log(res, '获取手机号需要的参数');
			let pc = new WXBizDataCrypt('你的小程序的APPID', this.session_key);
			let data = pc.decryptData(this.phone_encryptedData, this.phone_iv);
			console.log(data);
			if (data.phoneNumber != '') {
				this.phone = data.phoneNumber;
			}
		}
	}
};
</script>

<style lang="less" scoped>
.img {
	width: 574rpx;
	height: 436rpx;
	margin: 350rpx auto 0;
}
.phone {
	font-weight: 600;
	font-size: 40rpx;
	color: #333333;
}
.login {
	width: 640rpx;
	height: 96rpx;
	line-height: 96rpx;
	text-align: center;
	background: #fc132f;
	border-radius: 48rpx;
	font-weight: 600;
	font-size: 32rpx;
	color: #ffffff;
}
</style>
